package com.example.spinning.service;

import com.example.spinning.bean.InputStock;
import com.example.spinning.mapper.InputStockMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class InputStockService {

    @Autowired
    private InputStockMapper inputStockMapper;

    //得到入库单信息
    //带有分页功能的展现数据
    public List<InputStock> getAllInputStock(Integer page, Integer count) {
        int start = (page - 1) * count;
        return inputStockMapper.getInputStock(start,count);
    }

    //找到行数
    public int getInputStockCount() {
        return inputStockMapper.getCountInputStock();
    }

    //根据条件找到行数
    public int getInputStockCountByCondition(String unit,String date,String name,String function) {
        return inputStockMapper.getCountInputStockByCondition(unit,date,name,function);
    }

    //根据id查询入库单信息
    public InputStock getInputStockById(long id){
        InputStock stock = inputStockMapper.getInputStockById(id);
        return stock;
    }

    //根据条件模糊查询
    public List<InputStock> getInputStockByCondition(Integer page, Integer count,String unit,String date,String name,String function){
        int start = (page - 1) * count;
        return inputStockMapper.getInputStockByCondition(start,count,unit,date,name,function);
    }

    //添加入库单信息
    public int addInputStock(InputStock stock){
        return inputStockMapper.addInputStock(stock);
    }


    //修改
    public int updateInputStock(InputStock stock){
        return inputStockMapper.updateInputStockById(stock);
    }

    //删除
    public boolean deleteInputStockByIds(String ids){
        String[] split = ids.split(",");
        int result = inputStockMapper.delInputStockById(split);
        return result == split.length;
    }


}
